﻿#pragma once
#include "AsQBasicGlobal.h"
#include <QImage>

__AS_JY(Update 2023.1.7)
namespace As {

	AS_QBASIC_EXPORT cv::Mat cvRead(const QString& filepath, int flag = -1);

	AS_QBASIC_EXPORT bool cvWrite(const QString& path, const cv::Mat& mat);

	AS_QBASIC_EXPORT QImage cvMat2QImage(cv::Mat mat);

	AS_QBASIC_EXPORT cv::Mat QImage2cvMat(QImage image);

	AS_QBASIC_EXPORT QPoint toQPoint(const cv::Point& point);
	AS_QBASIC_EXPORT QPointF toQPointF(const cv::Point2f& point);
	AS_QBASIC_EXPORT QPointF toQPointF(const cv::Point2d& point);

	AS_QBASIC_EXPORT cv::Point toCvPoint(const QPoint& point);
	AS_QBASIC_EXPORT cv::Point2f toCvPoint2f(const QPointF& point);
	AS_QBASIC_EXPORT cv::Point2d toCvPoint2d(const QPointF& point);

	AS_QBASIC_EXPORT QSize toQSize(const cv::Size& point);
	AS_QBASIC_EXPORT QSizeF toQSizeF(const cv::Size2f& point);
	AS_QBASIC_EXPORT QSizeF toQSizeF(const cv::Size2d& point);

	AS_QBASIC_EXPORT QRect toQRect(const cv::Rect& rect);
	AS_QBASIC_EXPORT QRect toQRect(const cv::Mat& mat, cv::Point offset = cv::Point(0, 0));

	AS_QBASIC_EXPORT cv::Rect toCvRect(const QRect& rect);
	AS_QBASIC_EXPORT cv::Rect toRect(const cv::Mat& mat, cv::Point offset = cv::Point(0, 0));

	AS_QBASIC_EXPORT QString cvRectToQString(const cv::Rect& rect);

	AS_QBASIC_EXPORT cv::Rect qStringToCvRect(const QString& qstr);

	AS_QBASIC_EXPORT QVector<QPointF> toQPointFVector(const std::pair<cv::Point2f, cv::Point2f>& points);
	
	template <typename T>
	QVector<QPointF> toQPointFVector(const std::vector<T>& points) {
		QVector<QPointF> outputPoints;
		for (const auto& point : points) {
			outputPoints.push_back(QPointF(point.x, point.y));
		}
		return std::move(outputPoints);
	}

	template <typename T>
	QVector<QPointF> toQPointFVector(const std::vector<T>& points, double alpha) {
		QVector<QPointF> outputPoints;
		for (const auto& point : points) {
			outputPoints.push_back(QPointF(point.x * alpha, point.y * alpha));
		}
		return std::move(outputPoints);
	}

	template <typename T>
	std::vector<cv::Point2f> toCvPoint2fVector(const QVector<T>& points) {
		std::vector<cv::Point2f> outputPoints;
		for (const auto& point : points) {
			outputPoints.push_back(cv::Point2f(point.x(), point.y()));
		}
		return std::move(outputPoints);
	}

	AS_QBASIC_EXPORT QColor toQColor(const cv::Scalar& color);

};

